<div class="ibox float-e-margins">
    <div class="ibox-content" style="display: block;">

        <a no-pjax href="{{ route('admin.supplier.create') }}" class="btn btn-primary margin-bottom">新建供应商</a>

        <div class="box box-primary">

            <div class="box-body table-responsive">
                <table class="table table-hover table-bordered">
                    <tbody>
                    <!--tr-th start-->
                    <tr>
                        <th>供应商名称</th>
                        <th>编码</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    <!--tr-th end-->

                    @foreach ($suppliers as $item)
                        <tr>
                            <td>{{$item->name}}</td>
                            <td>{{$item->code}}</td>
                            <td>@if($item->status==1) 启用中 @else 已禁用 @endif</td>
                            <td>
                                @if($item->id!=1)
                                    <a no-pjax class="btn btn-xs btn-primary" href="{{route('admin.supplier.edit',['id'=>$item->id])}}"><i data-toggle="tooltip" data-placement="top" class="fa fa-pencil-square-o" title="编辑"></i>
                                    </a>
                                    <a class="btn btn-xs btn-danger delete" data-href="{{route('admin.supplier.delete',['id'=>$item->id])}}"><i data-toggle="tooltip" data-placement="top" class="fa fa-trash" title="删除"></i>
                                    </a>
                                @endif
                            </td>
                        </tr>
                    @endforeach

                    </tbody>
                </table>
            </div><!-- /.box-body -->
            <div class="box-footer clearfix">
            </div>
        </div>
    </div>
</div>
{{--@endsection

@section('before-scripts-end')--}}
<script>
    $(function () {
        $('.delete').on('click', function () {
            var that = $(this);
            var deleteUrl = that.data('href');

            swal({
                title: "确定要删除吗?",
                text: "",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确认",
                cancelButtonText: '取消',
                closeOnConfirm: false
            }, function () {
                $.post(deleteUrl, {token: _token}, function (result) {
                    if (result.status) {
                        swal({
                            title: "删除成功！",
                            text: "",
                            type: "success"
                        }, function () {
                            location = '{{route('admin.supplier.index')}}';
                        });
                    } else {
                        swal('删除失败', result.message, 'error');
                    }
                });
            });

        });
    });
</script>